cmake_minimum_required(VERSION 3.16)

project(systemui VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# if(NOT DEFINED INSTALL_EXAMPLESDIR)
#     set(INSTALL_EXAMPLESDIR "examples")
# endif()

# set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/demos/${PROJECT_NAME}")
# set(OUTPUT_DIRECTORY "${INSTALL_EXAMPLESDIR}/demos/${PROJECT_NAME}")



message("CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
    set(CMAKE_PREFIX_PATH /home/xqyr/Qt/5.15.2/gcc_64)
    set(SYSTEM_NAME linux64)
    set(LIB_PATH /mnt/i/nexcloud/windowsUp/Project/Imx6ullQT/midware/lib)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
    set(CMAKE_PREFIX_PATH C:/Qt/5.15.2/msvc2019)
    message("CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}")
    set(LIB_PATH I:/nexcloud/windowsUp/Project/Imx6ullQT/midware/lib)
    set(SYSTEM_NAME msv64)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")

elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
    set(SYSTEM_NAME arm32)
    set(LIB_PATH /mnt/i/nexcloud/windowsUp/Project/Imx6ullQT/midware/lib)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
    set(SYSTEM_NAME arm64)
else()
    set(SYSTEM_NAME win32)
endif()
message("CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick)
find_package(Qt${QT_VERSION_MAJOR}  REQUIRED COMPONENTS Core Quick)
message("protobuf_path ${LIB_PATH}/protobuf/${SYSTEM_NAME}")
find_package(Protobuf  REQUIRED PATHS
        PATHS "${LIB_PATH}/protobuf/${SYSTEM_NAME}"
        PATH_SUFFIXES "lib/cmake/protobuf" "cmake"
        NO_DEFAULT_PATH
)

file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")
set(PROJECT_SOURCES
        main.cpp
        qml.qrc

        ../../common/log/log.cpp
        ../../common/log/log.h

        ${SOURCES}
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(${PROJECT_NAME}
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
else()
    if(ANDROID)  

        add_library(${PROJECT_NAME} SHARED
            ${PROJECT_SOURCES}
        )
        set_property(TARGET screensaver APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
                     ${CMAKE_CURRENT_SOURCE_DIR}/purchasing/android)
        message("QT_ANDROID_PACKAGE_SOURCE_DIR ${QT_ANDROID_PACKAGE_SOURCE_DIR}")
    else()
        add_executable(${PROJECT_NAME}
                ${PROJECT_SOURCES}
        )

    endif()
endif()

target_include_directories(${PROJECT_NAME} PRIVATE
        ../../common
        ${LIB_PATH}/fdbus/${SYSTEM_NAME}/include
        ${LIB_PATH}/zlog/${SYSTEM_NAME}/include
        ${LIB_PATH}/protobuf/${SYSTEM_NAME}/include
)


target_link_libraries(${PROJECT_NAME}
  PRIVATE
        pthread
        protobuf::libprotobuf
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Quick

        ${LIB_PATH}/fdbus/${SYSTEM_NAME}/lib/libcommon_base.so
        ${LIB_PATH}/fdbus/${SYSTEM_NAME}/lib/libfdbus-clib.so
        ${LIB_PATH}/zlog/${SYSTEM_NAME}/lib/libzlog.so
)


# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.xqyr.${PROJECT_NAME})
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(QT_VERSION_MAJOR EQUAL 6)
    qt_import_qml_plugins(${PROJECT_NAME})
    qt_finalize_executable(${PROJECT_NAME})
endif()

target_include_directories(${PROJECT_NAME}
    PRIVATE   # 仅用于此目标的编译
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)
